﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco;
using umbraco.BasePages;
using umbraco.BusinessLogic;
using umbraco.interfaces;
using umbraco.controls;
using Commerce.Common;

namespace CommerceForUmbraco.adminSection.commerce
{
    public partial class dashboardProductSearch : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.pane_productsearch.Text = "Search Products";
            this.pp_prodsearch.Text = "Search";

            BindData();
        }

        protected void BindData()
        {
            // get collection values
            Commerce.Common.ProductCollection products = null;

            products = new ProductCollection().Where("productName", SubSonic.Comparison.Like, string.Format("%{0}%", searchText.Text)).OrderByAsc("productName").Load();
            //SubSonic.InlineQuery qry = new SubSonic.InlineQuery();
            //products = new ProductCollection();
            //products = qry.ExecuteAsCollection<ProductCollection>(String.Format("select * from dbo.CSK_Store_Product where productname LIKE '%{0}%'", searchText.Text.Trim()));
            //products.Sort("ProductName", true);

            gvProducts.DataSource = products;
            gvProducts.DataBind();
        }

        protected void searchButton_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}